<template>

  <el-dialog
    :close-on-click-modal="false"
    :visible.sync="visible">
    <h1 style="color: deepskyblue">密码修改</h1>
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
      <el-form-item label="旧密码" prop="oldPassword">
        <el-input v-model="dataForm.oldPassword" placeholder="旧密码"></el-input>
      </el-form-item>
    <el-form-item label="新密码" prop="newPasswordOne">
      <el-input v-model="dataForm.newPasswordOne" placeholder="新密码"></el-input>
    </el-form-item>
    <el-form-item label="确认密码" prop="newPasswordTwo">
      <el-input v-model="dataForm.newPasswordTwo" placeholder="确认新密码"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  import App from "../../App";
  import axios from "axios";
  export default {
    name: "studentInfoupdate",
    components: {App},
    data () {
      return {
        visible: false,
        dataForm: {
          oldPassword:'',
          newPasswordOne: '',
          newPasswordTwo: '',
        },
        dataRule: {
          oldPassword: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          newPasswordOne: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          newPasswordTwo: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
        },
        }
      },
    methods: {

      dataFormSubmit(){
        if (this.dataForm.newPasswordOne == this.dataForm.newPasswordTwo){
          axios.post('/api/app/updatePassword/',{
            oldPassword : this.dataForm.oldPassword,
            newPassword : this.dataForm.newPasswordTwo,
            stuId: localStorage.getItem("studentId")
          }).then((res)=> {
            console.log(res);
            this.$message(res.data.msg)
            this.visible = false
          })
        }else {
          this.$message.error("两次密码不一致！")
        }

      },
      init () {
        this.visible = true
        console.log(555);
      },
    }
  }
</script>
